package tutorial.lite_mod.schedule_system;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import public_util.model.Const4PublicDataBase;
import public_util.model.ReturnData;
import public_util.servlet.ServletParent;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 用来提供特殊接口给当前的小模式使用
 */
@Controller("/application_4_lite_mod_schedule_system")
public class Tutorial4LiteModServlet extends ServletParent {

    private static final long serialVersionUID = 1L;
    private static Logger logger = Logger.getLogger(Tutorial4LiteModServlet.class);




    /**
     * @see HttpServlet#HttpServlet()
     */
    public Tutorial4LiteModServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }



    /**
     */
    @RequestMapping("/application_4_lite_mod_schedule_system")
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String methodName = request.getParameter(Const4PublicDataBase.PARA_invoke_method);
        if (methodName!= null)
        {
            logger.info("--2--");
            super.doPost(request, response);
            return;
        }
        logger.info("--1--");

        //--提前打印出来
        ReturnData data  = new ReturnData();

        data.setStatus(0);
        printRes(response, data);
    }


    /**
     * 测试URL: application_4_lite_mod_schedule_system?invoke_method=show_test_demo&time=1000
     */
    public void show_test_demo(HttpServletRequest request, HttpServletResponse response) {
        ReturnData data =new ReturnData();
        data.setMsg("application_4_lite_mod_admin_power--->show_test_demo");
        data.setStatus(0);
        printRes(response, data);
    }

    /**
     * 批量产生相关学员的安排
     * 1.多个用户ID
     * 2.模板:一般是多个课程的一天模板;模板要区分周期:一天循环,一个礼拜循环、30天循环等
     * 3.安排的起始日期
     * 测试URL: application_4_lite_mod_schedule_system?invoke_method=batch_generate_arrange_4_student&&id_public_middle_table=55&id_public_user_info_list=3923&time_4_begin=2022-09-05&time_4_end=2022-09-16
     */
    public void batch_generate_arrange_4_student(HttpServletRequest request, HttpServletResponse response) {


        logger.info("-------batch_generate_arrange_4_student------");

        ReturnData returnData = Tutorial4LiteModTool.batch_generate_arrange_4_student(getSqlSession(), this, request.getSession(), response, request);
        if (returnData.getStatus() != 0)
        {
            printRes(response, returnData);
            return;
        }
        printRes(response, returnData);


    }


    /**
     * 修改学员的某天安排
     * 1.多个用户ID
     * 2.最小单元可以传入多个
     * 3.选择当天插入的数据
     * 测试URL: application_4_lite_mod_schedule_system?invoke_method=modify_arrange_4_student&id_public_middle_table=73,14&id_public_user_info_list=4323,4324&time_4_begin=2022-09-05
     */
    public void modify_arrange_4_student(HttpServletRequest request, HttpServletResponse response) {


        logger.info("-------modify_arrange_4_student------");

        ReturnData returnData = Tutorial4LiteModTool.modify_arrange_4_student(getSqlSession(), this, request.getSession(), response, request);
        if (returnData.getStatus() != 0)
        {
            printRes(response, returnData);
            return;
        }
        printRes(response, returnData);


    }

}